<template>
    <div>
        <div class="cmformItem"> 
            <div class="inputBox">
                <input type="password" v-model="pass1" placeholder="请设置新密码"/>
            </div>
        </div>
        <div class="cmformItem">
            <div class="inputBox">
                <input type="password" v-model="pass2" placeholder="请再次输入新密码"/>
            </div>
        </div>
        <div class="forgetBnt" @click="doSubmit">确定</div>
    </div>
</template>

<script setup>
import {ref} from 'vue'
import { updatePass } from '@/api/system'
import { message } from '@/utils/element'
import { ElMessageBox } from 'element-plus'

const props = defineProps({
    phone:''
})

const emit = defineEmits(['confirm'])

const pass1 = ref('')
const pass2 = ref('')

const doSubmit = async ()=>{
    if(!pass1.value){
        return message('请输入新密码',3)
    }else if(!pass2.value){
        return message('请再次输入新密码',3)
    }else if(pass1.value!=pass2.value){
        return message('两次输入的密码不一样！',3)
    }
    const res = await updatePass({
        newPassword: pass1.value,
        phone: props.phone,
        userType:1
    })
    if(!res.success){
        return message(res.message || '修改出错了',3)
    }
    
    ElMessageBox.alert('修改成功，请返回登录', '提示', {
        confirmButtonText: '确认',
        callback: (action) => {
            emit('confirm')
        },
    })
    
    
}
</script>